/**
 * Created by user on 2015/9/18.
 */

var bannerService = require('../../../services/mis/operate/bannerService');
var messageUtil = require('../../../common/utils/messageUtil');
var toolUtil = require('../../../common/utils/toolUtil');


exports.bannerList = function(req, res) {

    bannerService.bannerListService(req, function(err, results) {

        if (err) {
            logger.error('Exception happen when lotteryList...' + err.message);
            res.json(messageUtil.composeFailedMessage(req, 'Exception happen when lotteryList...'));
        }else {
            var data = {
                count:results[0]["count"],
                totalPage: results[0]["totalPage"],
                list: results[1]
            };
            res.json(messageUtil.composeSucceededMessage(req, null, data));
        }

    });
};

exports.bannerAdd = function (req, res) {

    bannerService.bannerAddService(req, function (err, result) {
        if (err) {
            logger.error('Exception happened when addPrize ...!' + err.message);
            res.json(messageUtil.composeFailedMessage(req, err.message));
        } else {
            res.json(messageUtil.composeSucceededMessage(req, null, result));
        }
    });
};

exports.bannerDelete = function (req, res) {

    bannerService.bannerDeleteService(req, function (err, result) {
        if (err) {
            logger.error('Exception happened when addPrize ...!' + err.message);
            res.json(messageUtil.composeFailedMessage(req, err.message));
        } else {
            res.json(messageUtil.composeSucceededMessage(req, null, result));
        }
    });
};


exports.bannerEdit = function (req, res) {

    bannerService.bannerEditService(req, function (err, result) {
        if (err) {
            logger.error('Exception happened when editbanner ...!' + err.message);
            res.json(messageUtil.composeFailedMessage(req, err.message));
        } else {
            res.json(messageUtil.composeSucceededMessage(req, null, result));
        }
    });
};

exports.bannerPush = function (req, res){

    bannerService.bannerPushService(req, function (err, result) {
        if (err) {
            logger.error('Exception happened when bannerPush ...!' + err.message);
            res.json(messageUtil.composeFailedMessage(req, err.message));
        } else {
            res.json(messageUtil.composeSucceededMessage(req, null, result));
        }
    });

};